package org.tloss.web.editor.database.editors;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.tloss.web.editor.database.editors.jdbc.Schema;
import org.tloss.web.editor.model.Database;

public class SchemaContentProvider implements ITreeContentProvider {


	@Override
	public void dispose() {

	}

	@Override
	public void inputChanged(Viewer arg0, Object arg1, Object arg2) {

	}

	@Override
	public Object[] getChildren(Object arg0) {

		return getElements(arg0);
	}

	private static final Object[] EMPTY = new Object[] {new Schema()};

	@Override
	public Object[] getElements(Object arg0) {
		if (arg0 instanceof Database) {
			Database database = (Database) arg0;
			if (database.getSchema() != null) {
				return new Object[] { database.getSchema() };
			}
		}
		return EMPTY;
	}

	@Override
	public Object getParent(Object arg0) {
		return null;
	}

	@Override
	public boolean hasChildren(Object element) {
		if (element instanceof Database) {
			return true;
		}
		return false;
	}

}
